import os
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String, Boolean, Numeric, Text, SmallInteger
from sqlalchemy.orm import sessionmaker

db_user = 'zhangyz'
db_password = '123456'
db_host = '10.4.7.13'
db_port = '3306'
db_name = 'school'
db_charset = 'utf8mb4'

# 构建数据库连接字符串
url = f"mysql://{db_user}:{db_password}@{db_host}:{db_port}/{db_name}?charset={db_charset}"

engine = create_engine(
    url=url,
    echo=True,  # 当设置为True时会将orm语句转化为sql语句打印, 一般debug的时候可用
    pool_size=8,  # 连接池的大小，默认为5个，设置为0时表示连接无限制
    pool_recycle=60 * 30  # 设置时间以限制数据库多久没连接自动断开
)

# 创建数据库连接
DBSession = sessionmaker(bind=engine)
session = DBSession()

# 创建数据库基类
Model = declarative_base()